package com.moneytalks.blazepoc.services {
	import com.moneytalks.blazepoc.dto.NoteDto;
	import com.moneytalks.blazepoc.dto.UserDto;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.Fault;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class NotebookServiceDelegateMock implements NotebookServiceDelegate {
		
		private static var mockNoteStorage:ArrayCollection;
		public function NotebookServiceDelegateMock() {
		}
		public function saveNote(note:NoteDto, responder:IResponder):void {
			if (null == mockNoteStorage) mockNoteStorage = new ArrayCollection();
			mockNoteStorage.addItem(note);
			var re:ResultEvent = new ResultEvent("MockSaveNoteEvent", false, true, note);
			responder.result(re);
		}
		public function retrieveNotes(userId:Number, responder:IResponder):void {
			var notes:ArrayCollection = new ArrayCollection();
			var note:NoteDto = new NoteDto();
			note.id = 666;
			note.url = "http://www.satyricon.no";
			note.content = "Satyricon homepage";
			note.userId = 1;
			
			notes.addItem(note);
			mockNoteStorage = notes;
			var re:ResultEvent = new ResultEvent("MockNotesEvent", false, true, notes);
			responder.result(re);
		}
		public function authenticate(username:String, password:String, responder:IResponder):void {
			if (username == "bob" && password == "bob") {
				var user:UserDto = new UserDto(1, username, password);
				var re:ResultEvent = new ResultEvent("MockNotesEvent", false, true, user);
				responder.result(re);
			} else {
				var f:Fault = new Fault("666", "Invalid username or password", "");
				var fe:FaultEvent = new FaultEvent("AuthenticationFailed", true, false, f)
				responder.fault(fe);
			}
			return;
		}
	}
}